<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\card\controller;

class Index extends \app\ApiRest
{
    protected $modelUser;
    protected $modelUserInfo;
    protected $modelCollection;
    protected $modelCompany;
    protected $modelConfig;
    protected $app;
    protected $noNeedLogin = ["getWxCodeData"];
    public function __construct(\think\App $app)
    {
        parent::__construct($app);
        $this->app = $app;
        $this->modelUser = new \app\card\model\User();
        $this->modelUserInfo = new \app\card\model\UserInfo();
        $this->modelCollection = new \app\card\model\Collection();
        $this->modelCompany = new \app\card\model\Company();
        $this->modelConfig = new \app\card\model\Config();
    }
    public function clearCacheData()
    {
        clearCache($this->_uniacid);
        return $this->success([]);
    }
    public function updateWechatInfo()
    {
        $userId = $this->getUserId();
        $userInfo = $this->getUserInfo();
        $verify = ["avatarUrl" => "", "city" => "", "country" => "", "gender" => "", "language" => "", "nickName" => "", "province" => ""];
        $params = lbGetParamVerify($this->_input, $verify);
        $result = \app\card\model\User::update($params, ["id" => $userId]);
        if($result === false) {
            return $this->error("update failed");
        }
        $key = "longbing_user_autograph_" . $userId;
        $key = md5($key);
        $userInfo["need_auth"] = 0;
        setCache($key, $userInfo, 3600, $this->_uniacid);
        if(!empty($params)) {
            $user = longbingGetUser($userId, $this->_uniacid);
            if(!empty($user)) {
                if(isset($params["avatarUrl"]) && !empty($params["avatarUrl"])) {
                    $user["avatarUrl"] = $params["avatarUrl"];
                }
                if(isset($params["city"]) && !empty($params["city"])) {
                    $user["city"] = $params["city"];
                }
                if(isset($params["country"]) && !empty($params["country"])) {
                    $user["country"] = $params["country"];
                }
                if(isset($params["gender"]) && !empty($params["gender"])) {
                    $user["gender"] = $params["gender"];
                }
                if(isset($params["language"]) && !empty($params["language"])) {
                    $user["language"] = $params["language"];
                }
                if(isset($params["nickName"]) && !empty($params["nickName"])) {
                    $user["nickName"] = $params["nickName"];
                }
                if(isset($params["province"]) && !empty($params["avataprovincerUrl"])) {
                    $user["province"] = $params["province"];
                }
                if(!in_array($user["avatarUrl"], [$this->defaultImage["avatar"]]) && !empty($user["avatarUrl"])) {
                    $user["need_auth"] = 0;
                }
                longbingSetUser($userId, $this->_uniacid, $user);
            }
        }
        return $this->success([]);
    }
    public function userCenter()
    {
        $userInfo = $this->getUserInfo();
        $userId = $this->getUserId();
        $userInfo = longbingGetUser($userId, $this->_uniacid);
        $page = isset($this->_param["page"]) ? $this->_param["page"] : 1;
        $checkCollection = $this->modelCollection->where([["uniacid", "=", $this->_uniacid], ["uid", "=", $userId], ["status", "=", 1]])->count();
        if($checkCollection) {
            $cardList = $this->modelCollection->bindCardList($userId, $userInfo, $page, $this->_uniacid);
        } else {
            $cardList = $this->modelCollection->defaultCardList($page, $this->_uniacid, $userId);
        }
        $cardList["is_staff"] = $userInfo["is_staff"];
        return $this->success($cardList, 200);
    }
    public function userInfo()
    {
        $uniacid = $this->_uniacid;
        $permissionAdmin = new \app\admin\info\PermissionAdmin($this->_uniacid);
        $longbing_auth_mini = $permissionAdmin->getAuthNumber();
        $userModel = new \app\card\model\User();
        $userInfoModel = new \app\card\model\UserInfo();
        $cardCountModel = new \app\card\model\CardCount();
        if($this->_is_weiqin) {
            $app_model_name = APP_MODEL_NAME;
            $wxapp = \think\facade\Db::name("account")->alias("a")->join("wxapp_versions v", "a.uniacid = v.uniacid")->join("account_wxapp account_wxapp", "a.uniacid = account_wxapp.uniacid")->field(["account_wxapp.name as mini_name", "account_wxapp.uniacid as  modular_id", "account_wxapp.uniacid"])->where([["v.modules", "like", "%" . $app_model_name . "%"], ["a.type", "=", 4], ["a.isdeleted", "=", 0]])->group("account_wxapp.uniacid")->order("account_wxapp.uniacid asc")->select()->toArray();
            $check_mini_user_count = count($wxapp);
            if($longbing_auth_mini < $check_mini_user_count) {
                foreach ($wxapp as $index => $item) {
                    $now = $index + 1;
                    if($item["uniacid"] == $uniacid && $longbing_auth_mini < $now) {
                        $msg = "小程序数量达到上限! 请联系管理员(" . $check_mini_user_count . "-" . $longbing_auth_mini . ")";
                        return $this->error($msg, 402);
                    }
                }
            }
        } else {
            $check_mini_user = $userModel->field("uniacid")->group("uniacid")->order("id asc")->select();
            $check_mini_user_count = count($check_mini_user);
            if($longbing_auth_mini < $check_mini_user_count) {
                foreach ($check_mini_user as $index => $item) {
                    $now = $index + 1;
                    if($item["uniacid"] == $uniacid && $longbing_auth_mini < $now) {
                        $msg = "小程序数量达到上限! 请联系管理员" . $check_mini_user_count . "-" . $longbing_auth_mini;
                        return $this->error($msg, 402);
                    }
                }
            }
            $check_mini_info = $userInfoModel->field("uniacid")->group("uniacid")->order("id asc")->select();
            $check_mini_info_count = count($check_mini_user);
            if($longbing_auth_mini < $check_mini_info_count) {
                foreach ($check_mini_info as $index => $item) {
                    $now = $index + 1;
                    if($item["uniacid"] == $uniacid && $longbing_auth_mini < $now) {
                        $msg = "小程序数量达到上限!! 请联系管理员" . $check_mini_info_count . "-" . $longbing_auth_mini;
                        return $this->error($msg, 402);
                    }
                }
            }
            $check_mini_count = $cardCountModel->field("uniacid")->group("uniacid")->order("id asc")->select();
            $check_mini_count_count = count($check_mini_user);
            if($longbing_auth_mini < $check_mini_count_count) {
                foreach ($check_mini_count as $index => $item) {
                    $now = $index + 1;
                    if($item["uniacid"] == $uniacid && $longbing_auth_mini < $now) {
                        $msg = "小程序数量达到上限!!! 请联系管理员" . $check_mini_count_count . "-" . $longbing_auth_mini;
                        return $this->error($msg, 402);
                    }
                }
            }
        }
        $user_id = $this->getUserId();
        $userInfo = longbingGetUser($user_id, $this->_uniacid);
        if(!empty($userInfo) && isset($userInfo["last_staff_id"])) {
            $staff_user = $userModel->where(["id" => $userInfo["last_staff_id"], "is_staff" => 1])->count();
            if(empty($staff_user)) {
                $collectionModel = new \app\card\model\Collection();
                $user["last_staff_id"] = $collectionModel->getCard($user_id, $uniacid);
                $userInfo = longbingGetUser($user_id, $this->_uniacid);
            }
        }
        $userInfo["cardInfo"] = [];
        if(isset($userInfo["is_staff"]) && $userInfo["is_staff"] == 1) {
            $key = "longbing_user_card_info_" . $userInfo["id"];
            $value = [];
            if($value && false) {
                $value["from_cache"] = 1;
                $userInfo["cardInfo"] = $value;
            } else {
                $cardInfo = longbingGetUserInfo($user_id, $this->_uniacid);
                if($cardInfo) {
                    $job = \app\card\model\Job::where([["id", "=", $cardInfo["job_id"]]])->find();
                    if(!$job) {
                        $cardInfo["job_name"] = "未设置职位";
                    } else {
                        $job = $job->toArray();
                        $cardInfo["job_name"] = $job["name"];
                    }
                    $cardInfo = transImages($cardInfo, ["images"], ",");
                    $cardInfo = transImagesOne($cardInfo, ["avatar", "voice", "my_url", "my_video", "my_video_cover", "bg", "vr_cover", "vr_path"]);
                    if(isset($cardInfo["my_video"]) && is_array($cardInfo["my_video"]) && !empty($cardInfo["my_video"])) {
                        $cardInfo["my_video_vid"] = lbGetTencentVideo($cardInfo["my_video"][0]);
                    }
                    $modelCount = new \app\radar\model\RadarCount();
                    list($viewCount, $thumbCount) = $modelCount->RadarNumber($userInfo["id"], $this->_uniacid);
                    $cardInfo["viewCount"] = $viewCount;
                    $cardInfo["thumbCount"] = $thumbCount;
                    $company = longbingGetUserCompany($cardInfo["company_id"], $uniacid);
                    if(isset($company["name"])) {
                        $company_name = $company["name"];
                    }
                    $cardInfo["company_info"] = $company;
                    $modelCompany = new \app\card\model\Company();
                    $cardInfo["company_info"] = $modelCompany->changeTopName($cardInfo["company_info"]);
                    $cardInfo["company_name"] = !empty($cardInfo["company_info"]["name"]) ? $cardInfo["company_info"]["name"] : $cardInfo["company_name"];
                    $radar_model = new \app\radar\model\RadarCount();
                    $cardInfo["share_number"] = $radar_model->getShareNumberV2($user_id);
                    $qrData = ["pid" => $this->_user_id, "staff_id" => $this->_user_id, "type" => 12, "key" => 1];
                    $src = "image/" . $this->_uniacid . "/" . "wxcode/" . md5($this->_uniacid . json_encode($qrData, true)) . ".jpeg";
                    if(!longbingHasLocalFile($src)) {
                        $push_data = ["action" => "longbingCreateWxCode", "event" => "longbingCreateWxCode", "uniacid" => $this->_uniacid, "data" => $qrData, "page" => "pages/user/home", "type" => 3];
                        publisher(json_encode($push_data, true));
                    }
                    $cardInfo["share_img"] = "images/share_img/" . $uniacid . "/share-" . $this->_user_id . ".png";
                    if(!longbingHasLocalFile($cardInfo["share_img"])) {
                        $user["share_img"] = NULL;
                        $cardInfo["share_img"] = NULL;
                    } else {
                        $cardInfo = transImagesOne($cardInfo, ["share_img"]);
                    }
                    $cardInfo["posterQr"] = $src;
                    $cardInfo = transImagesOne($cardInfo, ["posterQr"], $this->_uniacid);
                    $card_code_data = ["data" => ["staff_id" => (string) $user_id, "pid" => (string) $user_id, "type" => 4, "key" => 1]];
                    $qr_path = "image/" . $this->_uniacid . "/" . "wxcode/" . md5($this->_uniacid . json_encode($card_code_data, true)) . ".jpeg";
                    $cardInfo["qr_path"] = NULL;
                    if(longbingHasLocalFile($qr_path)) {
                        $cardInfo["qr_path"] = $qr_path;
                    } else {
                        $wxcode_data = longbingCreateWxCode($this->_uniacid, $card_code_data);
                        if(isset($wxcode_data["path"]) && !empty($wxcode_data["path"])) {
                            $cardInfo["qr_path"] = $wxcode_data["path"];
                        }
                    }
                    if(!empty($cardInfo["qr_path"])) {
                        $cardInfo = transImagesOne($cardInfo, ["qr_path"], $this->_uniacid);
                    }
                    $userInfo["cardInfo"] = $cardInfo;
                    setCache($key, $cardInfo, 1800, $this->_uniacid);
                    if(isset($cardInfo["share_text"]) && !empty($cardInfo["share_text"])) {
                        $share_text = $cardInfo["share_text"];
                        if(strpos($share_text, "#公司#")) {
                            $share_text = str_replace("#公司#", $company_name, $share_text);
                        }
                        if(strpos($share_text, "#职务#")) {
                            $share_text = str_replace("#职务#", $cardInfo["job_name"], $share_text);
                        }
                        if(strpos($share_text, "#我的名字#")) {
                            $share_text = str_replace("#我的名字#", $cardInfo["name"], $share_text);
                        }
                        if(strpos($share_text, "\$company")) {
                            $share_text = str_replace("\$company", $company_name, $share_text);
                        }
                        if(strpos($share_text, "\$job")) {
                            $share_text = str_replace("\$job", $cardInfo["job_name"], $share_text);
                        }
                        if(strpos($share_text, "\$name")) {
                            $share_text = str_replace("\$name", $cardInfo["name"], $share_text);
                        }
                        $userInfo["cardInfo"]["share_text"] = $share_text;
                    } else {
                        $userInfo["cardInfo"]["share_text"] = lang("card share text");
                    }
                }
            }
        }
        return $this->success($userInfo);
    }
    public function config()
    {
        $data = longbingGetAppConfig($this->_uniacid);
        unset($data["auth_code"]);
        $exist = \think\facade\Db::query("show tables like \"%longbing_card_config%\"");
        $auth_info = false;
        $cardauth2_config_exist = \think\facade\Db::query("show tables like \"%longbing_cardauth2_config%\"");
        if(!empty($exist) && !empty($cardauth2_config_exist)) {
            $auth_info = \think\facade\Db::name("longbing_cardauth2_config")->where([["modular_id", "=", $this->_uniacid]])->find();
        }
        $data["is_pay_shop"] = 1;
        if($auth_info && isset($auth_info["pay_shop"]) && $auth_info["pay_shop"] == 0) {
            $data["is_pay_shop"] = 0;
        }
        if(isset($data["btn_talk"]) && !$data["btn_talk"]) {
            $data["btn_talk"] = "面议";
        }
        $data["tabBar1"] = [];
        $data["tabBar1"] = \longbingcore\permissions\Tabbar::all($this->_uniacid, $this->_user_id);
        $pluginAuth = longbingGetPluginAuth($this->_uniacid, $this->_user_id, $auth_info);
        $data = array_merge($data, $pluginAuth);
        return $this->success($data);
    }
    public function cardType()
    {
        $userId = $this->getUserId();
        $card = \app\card\model\UserInfo::where([["fans_id", "=", $userId], ["is_staff", "=", 1], ["uniacid", "=", $this->_uniacid]])->field(["card_type"])->find();
        if(!$card) {
            $this->error("card info not found", 402);
        }
        $modelCardType = new \app\card\model\CardType();
        $count = $modelCardType->where([["uniacid", "=", $this->_uniacid]])->count();
        if(!$count) {
            $data = $modelCardType->initCardType($this->_uniacid);
        } else {
            $data = $modelCardType->where([["uniacid", "=", $this->_uniacid], ["status", "=", 1]])->field(["card_type", "img"])->select();
        }
        foreach ($data as $index => $item) {
            $data[$index]["selected"] = 0;
            if($item["card_type"] == $card->card_type) {
                $data[$index]["selected"] = 1;
            }
        }
        return $this->success($data);
    }
    public function editCardType()
    {
        $userId = $this->getUserId();
        $verify = ["card_type" => "required"];
        $params = lbGetParamVerify($this->_input, $verify);
        $card = \app\card\model\UserInfo::where([["fans_id", "=", $userId], ["is_staff", "=", 1], ["uniacid", "=", $this->_uniacid]])->field(["card_type"])->find();
        if(!$card) {
            $this->error("card info not found", 402);
        }
        $card->card_type = $params["card_type"];
        $result = $card->save();
        if($result === false) {
            $this->error("edit fail", 402);
        } else {
            $key = "longbing_card_card_info_" . $userId;
            delCache($key, $this->_uniacid);
        }
        return $this->success([]);
    }
    public function editCardVoice()
    {
        $userId = $this->getUserId();
        $verify = ["voice_id" => "required", "voice_time" => 0];
        $params = lbGetParamVerify($this->_input, $verify);
        $card = \app\card\model\UserInfo::where([["fans_id", "=", $userId], ["is_staff", "=", 1], ["uniacid", "=", $this->_uniacid]])->field(["voice", "voice_time"])->find();
        if(!$card) {
            $this->error("card info not found", 402);
        }
        $card->voice = $params["voice_id"];
        $card->voice_time = $params["voice_time"];
        $result = $card->save();
        if($result === false) {
            $this->error("edit fail", 402);
        } else {
            $key = "longbing_card_info_" . $userId;
            delCache($key, $this->_uniacid);
            longbingGetUserInfo($userId, $this->_uniacid, true);
        }
        return $this->success([]);
    }
    public function reviewData()
    {
        $userId = $this->getUserId();
        $userInfo = $this->getUserInfo();
        $modelCompany = new \app\card\model\Company();
        $modelJob = new \app\card\model\CardJob();
        $modelType = new \app\card\model\CardType();
        $card = \app\card\model\UserInfo::where([["uniacid", "=", $this->_uniacid], ["fans_id", "=", $userId]])->find();
        if($card) {
            $card = $card->toArray();
            $data = transImagesOne($card, ["avatar"], $this->_uniacid);
            $data["companyList"] = $modelCompany->getListByUser($userId, $this->_uniacid, 0, $card["company_id"]);
            $data["jobList"] = $modelJob->getListByUser($card["job_id"], $this->_uniacid);
            $data["typeList"] = $modelType->getCardTypeList($this->_uniacid, $card["card_type"]);
            $data["company_info"] = $modelCompany->getInfo($this->_uniacid, 0, $card["company_id"]);
            if(!empty($data["company_info"])) {
                $data["company_info"]["top_name"] = $modelCompany->where(["id" => $data["company_info"]["top_id"], "status" => 1])->value("name");
            }
        } else {
            $data = ["avatar" => $userInfo["avatarUrl"], "name" => $userInfo["nickName"], "phone" => $userInfo["phone"], "email" => ""];
            $data["companyList"] = $modelCompany->getListByUser($userId, $this->_uniacid, 1, 0);
            $data["jobList"] = $modelJob->getListByUser(0, $this->_uniacid);
            $data["typeList"] = $modelType->getCardTypeList($this->_uniacid);
            $data["company_info"] = [];
        }
        $config = $this->modelConfig->getConfig($this->_uniacid);
        $data["job_switch"] = $config["job_switch"];
        return $this->success($data);
    }
    public function cardInfo()
    {
        $userId = $this->getUserId();
        $uniacid = $this->_uniacid;
        $verify = ["staff_id" => "required"];
        $params = lbGetParamVerify($this->_param, $verify);
        $staff_id = $params["staff_id"];
        $staff = longbingGetUserInfo($staff_id, $this->_uniacid);
        if(empty($staff) || empty($staff["is_staff"])) {
            return $this->error(lang("card info not found"), 403);
        }
        $card = \app\card\model\UserInfo::alias("a")->field(["a.*", "b.name as job_name"])->join("longbing_card_job b", "a.job_id = b.id", "LEFT")->where([["a.fans_id", "=", $params["staff_id"]], ["a.is_staff", "=", 1], ["a.uniacid", "=", $this->_uniacid]])->find();
        if(empty($card)) {
            return $this->error(lang("card info not found"), 403);
        }
        if(!in_array($userId, [$params["staff_id"]])) {
            $user_update = \app\card\model\User::update(["last_staff_id" => $params["staff_id"]], ["id" => $userId]);
            if(!empty($user_update)) {
                $user = longbingGetUser($userId, $this->_uniacid);
                $user["last_staff_id"] = $params["staff_id"];
                longbingSetUser($userId, $this->_uniacid, $user);
            }
        }
        $cardInfo = $card->toArray();
        if(!$cardInfo["job_name"]) {
            $cardInfo["job_name"] = lang("not set job");
        }
        if(!isset($cardInfo["vr_tittle"]) || empty($cardInfo["vr_tittle"])) {
            $config = longbingGetAppConfig($this->_uniacid);
            if(!empty($config) && !empty($config["vr_tittle"])) {
                $cardInfo["vr_tittle"] = $config["vr_tittle"];
            } else {
                $cardInfo["vr_tittle"] = lang("panoramic");
            }
        }
        $modelConfig = new \app\card\model\Config();
        $config = longbingGetAppConfig($this->_uniacid);
        if(!$cardInfo["bg"]) {
            $cardInfo["bg"] = $config["default_voice"];
        }
        if(!$cardInfo["bg_switch"]) {
            $cardInfo["bg_switch"] = $config["default_voice_switch"];
        }
        $cardInfo = transImages($cardInfo, ["images"], ",");
        $cardInfo = transImagesOne($cardInfo, ["avatar", "voice", "my_url", "my_video", "my_video_cover", "bg", "vr_cover", "vr_path"]);
        $modelCount = new \app\radar\model\RadarCount();
        list($viewCount, $thumbCount) = $modelCount->RadarNumber($cardInfo["fans_id"], $this->_uniacid);
        $cardInfo["viewCount"] = $viewCount;
        $cardInfo["thumbCount"] = $thumbCount;
        list($cardInfo["view_list"], $cardInfo["view_count"]) = $modelCount->getCardViewInfo($params["staff_id"], $this->_uniacid);
        $modelCompany = new \app\card\model\Company();
        if($cardInfo["company_id"]) {
            $card_company = new \app\company\model\CardCompany();
            $company_id = $card_company->getUserTopCompanyId($cardInfo["company_id"]);
            $company = $card_company->getinfo(["uniacid" => $this->_uniacid, "id" => $company_id]);
        } else {
            $company = $modelCompany->getInfo($this->_uniacid, 0, 0);
        }
        $cardInfo["company_info"] = $company;
        $company_name = "";
        if(isset($company["name"])) {
            $company_name = $company["name"];
        }
        $card_code_data = ["data" => ["staff_id" => $params["staff_id"], "pid" => $userId, "type" => 4, "key" => 1]];
        $qr_path = "image/" . $this->_uniacid . "/" . "wxcode/" . md5($this->_uniacid . json_encode($card_code_data, true)) . "jpeg";
        $cardInfo["qr_path"] = NULL;
        if(longbingHasLocalFile($qr_path)) {
            $cardInfo["qr_path"] = $qr_path;
        } else {
            $wxcode_data = longbingCreateWxCode($this->_uniacid, $card_code_data);
            if(isset($wxcode_data["path"]) && !empty($wxcode_data["path"])) {
                $cardInfo["qr_path"] = $wxcode_data["path"];
            }
        }
        if(!empty($cardInfo["qr_path"])) {
            $cardInfo = transImagesOne($cardInfo, ["qr_path"]);
        }
        if(isset($cardInfo["share_text"]) && !empty($cardInfo["share_text"])) {
            $share_text = $cardInfo["share_text"];
            if(strpos($share_text, "#公司#")) {
                $share_text = str_replace("#公司#", $company_name, $share_text);
            }
            if(strpos($share_text, "#职务#")) {
                $share_text = str_replace("#职务#", $cardInfo["job_name"], $share_text);
            }
            if(strpos($share_text, "#我的名字#")) {
                $share_text = str_replace("#我的名字#", $cardInfo["name"], $share_text);
            }
            if(strpos($share_text, "\$company")) {
                $share_text = str_replace("\$company", $company_name, $share_text);
            }
            if(strpos($share_text, "\$job")) {
                $share_text = str_replace("\$job", $cardInfo["job_name"], $share_text);
            }
            if(strpos($share_text, "\$name")) {
                $share_text = str_replace("\$name", $cardInfo["name"], $share_text);
            }
            $cardInfo["share_text"] = $share_text;
        } else {
            $cardInfo["share_text"] = lang("card share text");
        }
        $cardInfo["share_img"] = "images/share_img/" . $uniacid . "/share-" . $staff_id . ".png";
        if(!longbingHasLocalFile($cardInfo["share_img"])) {
            $user["share_img"] = NULL;
            $cardInfo["share_img"] = NULL;
        } else {
            $cardInfo = transImagesOne($cardInfo, ["share_img"]);
        }
        if(isset($config["default_video"]) && empty($cardInfo["my_video"])) {
            $cardInfo["my_video"] = $config["default_video"];
        }
        if(isset($config["default_video_cover"]) && empty($cardInfo["my_video_cover"])) {
            $cardInfo["my_video_cover"] = $config["default_video_cover"];
        }
        if(isset($config["default_voice"]) && empty($cardInfo["bg"])) {
            $cardInfo["bg"] = $config["default_voice"];
        }
        if(isset($config["vr_cover"]) && empty($cardInfo["vr_cover"])) {
            $cardInfo["vr_cover"] = $config["vr_cover"];
        }
        if(isset($config["vr_path"]) && empty($cardInfo["vr_path"])) {
            $cardInfo["vr_path"] = $config["vr_path"];
            $cardInfo["vr_switch"] = $config["vr_switch"];
        }
        if(isset($config["vr_tittle"]) && empty($cardInfo["vr_tittle"])) {
            $cardInfo["vr_tittle"] = $config["vr_tittle"];
        }
        if(isset($cardInfo["my_video"]) && $cardInfo["my_video"]) {
            $cardInfo["my_video_vid"] = lbGetTencentVideo($cardInfo["my_video"]);
        }
        $modelTags = new \app\card\model\CardTags();
        $cardInfo["tag_list"] = $modelTags->cardTagList($params["staff_id"], $userId, $this->_uniacid);
        if(isset($cardInfo["vr_tittle"]) && !$cardInfo["vr_tittle"]) {
            $cardInfo["vr_tittle"] = "VR全景";
        }
        $checkVoice = \app\card\model\CardCount::where([["type", "=", 1], ["user_id", "=", $userId], ["to_uid", "=", $params["staff_id"]], ["sign", "=", "praise"]])->count();
        $checkThumb = \app\card\model\CardCount::where([["type", "=", 3], ["user_id", "=", $userId], ["to_uid", "=", $params["staff_id"]], ["sign", "=", "praise"]])->count();
        $radar_model = new \app\radar\model\RadarCount();
        $share_number = $radar_model->getShareNumberV2($params["staff_id"]);
        if($checkVoice) {
            $cardInfo["voiceThumbs"] = 1;
        } else {
            $cardInfo["voiceThumbs"] = 0;
        }
        if($checkThumb) {
            $cardInfo["isThumbs"] = 1;
        } else {
            $cardInfo["isThumbs"] = 0;
        }
        $cardInfo["view_count"] = $cardInfo["view_count"] + $cardInfo["view_number"];
        $cardInfo["thumbCount"] = $cardInfo["thumbCount"] + $cardInfo["t_number"];
        $cardInfo["share_number"] = $share_number;
        $time = time();
        $coupon = \app\card\model\CardCoupon::where([["end_time", ">", $time], ["status", "=", 1], ["uniacid", "=", $this->_uniacid], ["number", ">", 0]])->order(["top" => "desc", "id" => "desc"])->select()->toArray();
        $cardInfo["coupon"] = [];
        $cardInfo["coupon_last_record"] = [];
        $cardInfo["coupon_last_record_user"] = [];
        if($coupon) {
            foreach ($coupon as $index => $item) {
                $record_list = \app\card\model\CardCouponRecord::where([["coupon_id", "=", $item["id"]], ["staff_id", "=", $params["staff_id"]], ["uniacid", "=", $this->_uniacid]])->order(["id" => "desc"])->select()->toArray();
                if(count($record_list) < $item["number"]) {
                    $cardInfo["coupon"] = $item;
                    if(count($record_list)) {
                        $cardInfo["coupon_last_record"] = $record_list;
                    }
                }
            }
        }
        if(!empty($cardInfo["coupon_last_record"])) {
            foreach ($cardInfo["coupon_last_record"] as $index => $item) {
                $user = longbingGetUser($item["user_id"], $this->_uniacid);
                if(4 < mb_strlen($user["nickName"], "utf8")) {
                    $user["nickName"] = mb_substr($user["nickName"], 0, 4, "UTF-8");
                }
                $cardInfo["coupon_last_record"][$index]["user_info"] = $user;
            }
        }
        return $this->success($cardInfo);
    }
    public function cardInfoV2()
    {
        $userId = (string) $this->getUserId();
        $uniacid = $this->_uniacid;
        $verify = ["staff_id" => "required", "is_base" => 0];
        $params = lbGetParamVerify($this->_param, $verify);
        $input = $this->_param;
        $staff_id = $params["staff_id"];
        $cardInfo = longbingGetUserCard($staff_id, $this->_uniacid);
        if(empty($cardInfo) || empty($cardInfo["is_staff"])) {
            return $this->error(lang("card info not found"), 403);
        }
        if(!$cardInfo["job_name"]) {
            $cardInfo["job_name"] = lang("not set job");
        }
        $card_code_data = ["data" => ["staff_id" => $params["staff_id"], "pid" => $userId, "type" => 4, "key" => 1]];
        $qr_path = "image/" . $this->_uniacid . "/" . "wxcode/" . md5($this->_uniacid . json_encode($card_code_data, true)) . ".jpeg";
        if(!longbingHasLocalFile($qr_path)) {
            $push_data = ["action" => "longbingCreateWxCode", "event" => "longbingCreateWxCode", "uniacid" => $this->_uniacid, "data" => $card_code_data, "page" => "", "type" => 3];
            publisher(json_encode($push_data, true));
        }
        $cardInfo["qr_path"] = $qr_path;
        if(!empty($cardInfo["qr_path"])) {
            $cardInfo = transImagesOne($cardInfo, ["qr_path"]);
        }
        $modelCompany = new \app\card\model\Company();
        if(empty($cardInfo["company_info"])) {
            $company = $modelCompany->getInfo($this->_uniacid, $cardInfo["fans_id"], 0);
            $cardInfo["company_info"] = $company;
            if(isset($company["name"])) {
                $company_name = $company["name"];
            }
        }
        $cardInfo["company_info"] = $modelCompany->changeTopName($cardInfo["company_info"]);
        $cardInfo["company_name"] = !empty($cardInfo["company_info"]["name"]) ? $cardInfo["company_info"]["name"] : $cardInfo["company_name"];
        if(isset($cardInfo["share_text"]) && !empty($cardInfo["share_text"])) {
            $share_text = $cardInfo["share_text"];
            if(strpos($share_text, "#公司#")) {
                $share_text = str_replace("#公司#", $cardInfo["company_name"], $share_text);
            }
            if(strpos($share_text, "#职务#")) {
                $share_text = str_replace("#职务#", $cardInfo["job_name"], $share_text);
            }
            if(strpos($share_text, "#我的名字#")) {
                $share_text = str_replace("#我的名字#", $cardInfo["name"], $share_text);
            }
            if(strpos($share_text, "\$company")) {
                $share_text = str_replace("\$company", $cardInfo["company_name"], $share_text);
            }
            if(strpos($share_text, "\$job")) {
                $share_text = str_replace("\$job", $cardInfo["job_name"], $share_text);
            }
            if(strpos($share_text, "\$name")) {
                $share_text = str_replace("\$name", $cardInfo["name"], $share_text);
            }
            $cardInfo["share_text"] = $share_text;
        } else {
            $cardInfo["share_text"] = "您好，我是" . $cardInfo["company_name"] . "的" . $cardInfo["job_name"] . $cardInfo["name"] . ",请惠存";
        }
        $cardInfo["share_img"] = "images/share_img/" . $uniacid . "/share-" . $staff_id . ".png";
        if(!longbingHasLocalFile($cardInfo["share_img"])) {
            $user["share_img"] = NULL;
            $cardInfo["share_img"] = NULL;
        } else {
            $cardInfo = transImagesOne($cardInfo, ["share_img"]);
        }
        $user_update = \app\card\model\User::update(["last_staff_id" => $params["staff_id"]], ["id" => $userId]);
        if(!empty($user_update)) {
            $user = longbingGetUser($userId, $this->_uniacid);
            $user["last_staff_id"] = $params["staff_id"];
            longbingSetUser($userId, $this->_uniacid, $user);
        }
        if(isset($params["is_base"]) && !empty($params["is_base"])) {
            $cardInfo = transImagesOne($cardInfo, ["avatar"]);
            return $this->success($cardInfo);
        }
        if(!isset($cardInfo["vr_tittle"]) || empty($cardInfo["vr_tittle"])) {
            $config = longbingGetAppConfig($this->_uniacid);
            if(!empty($config) && !empty($config["vr_tittle"])) {
                $cardInfo["vr_tittle"] = $config["vr_tittle"];
            } else {
                $cardInfo["vr_tittle"] = lang("panoramic");
            }
        }
        $config = longbingGetAppConfig($this->_uniacid);
        if(!$cardInfo["bg"]) {
            $cardInfo["bg"] = $config["default_voice"];
        }
        if(!$cardInfo["bg_switch"]) {
            $cardInfo["bg_switch"] = $config["default_voice_switch"];
        }
        $cardInfo = transImages($cardInfo, ["images"], ",");
        $cardInfo = transImagesOne($cardInfo, ["avatar", "voice", "my_url", "my_video", "my_video_cover", "bg", "vr_cover", "vr_path"]);
        $config = longbingGetAppConfig($this->_uniacid);
        if(isset($config["default_video"]) && empty($cardInfo["my_video"])) {
            $cardInfo["my_video"] = $config["default_video"];
        }
        if(isset($config["default_video_cover"]) && empty($cardInfo["my_video_cover"])) {
            $cardInfo["my_video_cover"] = $config["default_video_cover"];
        }
        if(isset($config["default_voice"]) && empty($cardInfo["bg"])) {
            $cardInfo["bg"] = $config["default_voice"];
        }
        if(isset($config["vr_cover"]) && empty($cardInfo["vr_cover"])) {
            $cardInfo["vr_cover"] = $config["vr_cover"];
        }
        if(isset($config["vr_path"]) && empty($cardInfo["vr_path"])) {
            $cardInfo["vr_path"] = $config["vr_path"];
            $cardInfo["vr_switch"] = $config["vr_switch"];
        }
        if(isset($config["vr_tittle"]) && empty($cardInfo["vr_tittle"])) {
            $cardInfo["vr_tittle"] = $config["vr_tittle"];
        }
        if(isset($cardInfo["my_video"]) && $cardInfo["my_video"]) {
            $cardInfo["my_video_vid"] = lbGetTencentVideo($cardInfo["my_video"]);
        }
        if(isset($cardInfo["vr_tittle"]) && !$cardInfo["vr_tittle"]) {
            $cardInfo["vr_tittle"] = "VR全景";
        }
        if(isset($input["is_update"]) && $input["is_update"] != 1) {
            $defult_setting = new \app\card\model\DefaultSetting();
            $defult_setting_data = $defult_setting->settingInfo(["uniacid" => $this->_uniacid]);
            $defult_setting_data = transImages($defult_setting_data, ["my_photo_cover"]);
            $cardInfo["desc"] = !empty($cardInfo["desc"]) ? $cardInfo["desc"] : $defult_setting_data["my_sign"];
            $cardInfo["images"] = !empty($cardInfo["images"]) ? $cardInfo["images"] : $defult_setting_data["my_photo_cover"];
            $cardInfo["my_url"] = !empty($cardInfo["my_url"]) ? $cardInfo["my_url"] : $defult_setting_data["my_photo_link"];
            $cardInfo["voice"] = !empty($cardInfo["voice"]) ? $cardInfo["voice"] : $defult_setting_data["voice_text"];
            $cardInfo["voice_time"] = !empty($cardInfo["voice_time"]) ? $cardInfo["voice_time"] : $defult_setting_data["voice_time"];
        }
        $coupon_dis = ["status" => 1, "uniacid" => $this->_uniacid];
        $coupon_model = new \app\shop\model\IndexCoupon();
        $coupon = $coupon_model->couponListSelect($coupon_dis, $this->getUserId(), $staff_id, 100);
        $cardInfo["coupon"] = [];
        $cardInfo["coupon_last_record"] = [];
        $cardInfo["coupon_last_record_user"] = [];
        if($coupon) {
            foreach ($coupon as $index => $item) {
                $record_list = \app\card\model\CardCouponRecord::where([["coupon_id", "=", $item["id"]], ["staff_id", "=", $params["staff_id"]], ["uniacid", "=", $this->_uniacid]])->order(["id" => "desc"])->select()->toArray();
                if(count($record_list) < $item["number"]) {
                    $cardInfo["coupon"] = $item;
                    if(count($record_list)) {
                        $cardInfo["coupon_last_record"] = $record_list;
                    }
                }
            }
        }
        if(!empty($cardInfo["coupon_last_record"])) {
            foreach ($cardInfo["coupon_last_record"] as $index => $item) {
                $user = longbingGetUser($item["user_id"], $this->_uniacid);
                if(4 < mb_strlen($user["nickName"], "utf8")) {
                    $user["nickName"] = mb_substr($user["nickName"], 0, 4, "UTF-8");
                }
                $cardInfo["coupon_last_record"][$index]["user_info"] = $user;
            }
        }
        $modelCount = new \app\radar\model\RadarCount();
        list($viewCount, $thumbCount) = $modelCount->RadarNumber($staff_id, $this->_uniacid);
        $cardInfo["view_count"] = $viewCount;
        $cardInfo["thumbCount"] = $thumbCount;
        $checkVoice = \app\card\model\CardCount::where([["type", "=", 1], ["user_id", "=", $userId], ["to_uid", "=", $params["staff_id"]], ["sign", "=", "praise"]])->count();
        $checkThumb = \app\card\model\CardCount::where([["type", "=", 3], ["user_id", "=", $userId], ["to_uid", "=", $params["staff_id"]], ["sign", "=", "praise"]])->count();
        $radar_model = new \app\radar\model\RadarCount();
        $share_number = $radar_model->getShareNumber($params["staff_id"]);
        if($checkVoice) {
            $cardInfo["voiceThumbs"] = 1;
        } else {
            $cardInfo["voiceThumbs"] = 0;
        }
        if($checkThumb) {
            $cardInfo["isThumbs"] = 1;
        } else {
            $cardInfo["isThumbs"] = 0;
        }
        $cardInfo["view_count"] = $cardInfo["view_count"] + $cardInfo["view_number"];
        $cardInfo["thumbCount"] = $cardInfo["thumbCount"] + $cardInfo["t_number"];
        $cardInfo["share_number"] = $share_number;
        $modelTags = new \app\card\model\CardTags();
        $cardInfo["tag_list"] = $modelTags->cardTagList($params["staff_id"], $userId, $this->_uniacid);
        $eventCardInfoData = event("CardInfo", $params);
        foreach ($eventCardInfoData as $items) {
            foreach ($items as $key => $item) {
                if($key == "decorate") {
                    $cardInfo["plugin"] = $item;
                } else {
                    $cardInfo[$key] = $item;
                }
            }
        }
        return $this->success($cardInfo);
    }
    public function cardInfoV3()
    {
        $diy_data = \app\diy\model\DiyModel::where([["status", "=", 1], ["uniacid", "=", $this->_uniacid]])->find();
        $page_data = json_decode($diy_data["page"], true)[1] ?? [];
        if(empty($page_data) || array_key_exists("list", $page_data) && empty($page_data["list"])) {
            $page_data = longbing_default_Page(1);
        }
        $userId = (string) $this->getUserId();
        $uniacid = $this->_uniacid;
        $verify = ["staff_id" => "required", "is_base" => 0];
        $params = lbGetParamVerify($this->_param, $verify);
        $input = $this->_param;
        $staff_id = $params["staff_id"];
        $cardInfo = longbingGetUserCard($staff_id, $this->_uniacid);
        if(empty($cardInfo) || empty($cardInfo["is_staff"])) {
            return $this->error(lang("card info not found"), 403);
        }
        if(!$cardInfo["job_name"]) {
            $cardInfo["job_name"] = lang("not set job");
        }
        $card_code_data = ["data" => ["staff_id" => $params["staff_id"], "pid" => $userId, "type" => 4, "key" => 1]];
        $qr_path = "image/" . $this->_uniacid . "/" . "wxcode/" . md5($this->_uniacid . json_encode($card_code_data, true)) . ".jpeg";
        if(longbingHasLocalFile($qr_path)) {
            $cardInfo["qr_path"] = $qr_path;
        } else {
            $push_data = ["action" => "longbingCreateWxCode", "event" => "longbingCreateWxCode", "uniacid" => $this->_uniacid, "data" => $card_code_data, "page" => "", "type" => 3];
            publisher(json_encode($push_data, true));
            $cardInfo["qr_path"] = $qr_path;
        }
        if(!empty($cardInfo["qr_path"])) {
            $cardInfo = transImagesOne($cardInfo, ["qr_path"]);
        }
        $modelCompany = new \app\card\model\Company();
        if(empty($cardInfo["company_info"])) {
            $company = $modelCompany->getInfo($this->_uniacid, $cardInfo["fans_id"], 0);
            $cardInfo["company_info"] = $company;
            if(isset($company["name"])) {
                $company_name = $company["name"];
            }
        }
        $cardInfo["company_info"] = $modelCompany->changeTopName($cardInfo["company_info"]);
        $cardInfo["company_name"] = !empty($cardInfo["company_info"]["name"]) ? $cardInfo["company_info"]["name"] : $cardInfo["company_name"];
        if(isset($cardInfo["share_text"]) && !empty($cardInfo["share_text"])) {
            $share_text = $cardInfo["share_text"];
            if(strpos($share_text, "#公司#")) {
                $share_text = str_replace("#公司#", $cardInfo["company_name"], $share_text);
            }
            if(strpos($share_text, "#职务#")) {
                $share_text = str_replace("#职务#", $cardInfo["job_name"], $share_text);
            }
            if(strpos($share_text, "#我的名字#")) {
                $share_text = str_replace("#我的名字#", $cardInfo["name"], $share_text);
            }
            if(strpos($share_text, "\$company")) {
                $share_text = str_replace("\$company", $cardInfo["company_name"], $share_text);
            }
            if(strpos($share_text, "\$job")) {
                $share_text = str_replace("\$job", $cardInfo["job_name"], $share_text);
            }
            if(strpos($share_text, "\$name")) {
                $share_text = str_replace("\$name", $cardInfo["name"], $share_text);
            }
            $cardInfo["share_text"] = $share_text;
        } else {
            $cardInfo["share_text"] = "您好，我是" . $cardInfo["company_name"] . "的" . $cardInfo["job_name"] . $cardInfo["name"] . ",请惠存";
        }
        $cardInfo["share_img"] = "images/share_img/" . $uniacid . "/share-" . $staff_id . ".png";
        if(!longbingHasLocalFile($cardInfo["share_img"])) {
            $user["share_img"] = NULL;
            $cardInfo["share_img"] = NULL;
        } else {
            $cardInfo = transImagesOne($cardInfo, ["share_img"]);
        }
        $user_update = \app\card\model\User::update(["last_staff_id" => $params["staff_id"]], ["id" => $userId]);
        if(!empty($user_update)) {
            $user = longbingGetUser($userId, $this->_uniacid);
            $user["last_staff_id"] = $params["staff_id"];
            longbingSetUser($userId, $this->_uniacid, $user);
        }
        if(isset($params["is_base"]) && !empty($params["is_base"])) {
            $cardInfo = transImagesOne($cardInfo, ["avatar"]);
            return $this->success($cardInfo);
        }
        if(!isset($cardInfo["vr_tittle"]) || empty($cardInfo["vr_tittle"])) {
            $config = longbingGetAppConfig($this->_uniacid);
            if(!empty($config) && !empty($config["vr_tittle"])) {
                $cardInfo["vr_tittle"] = $config["vr_tittle"];
            } else {
                $cardInfo["vr_tittle"] = lang("panoramic");
            }
        }
        $config = longbingGetAppConfig($this->_uniacid);
        if(!$cardInfo["bg"]) {
            $cardInfo["bg"] = $config["default_voice"];
        }
        if(!$cardInfo["bg_switch"]) {
            $cardInfo["bg_switch"] = $config["default_voice_switch"];
        }
        $cardInfo = transImages($cardInfo, ["images"], ",");
        $cardInfo = transImagesOne($cardInfo, ["avatar", "voice", "my_url", "my_video", "my_video_cover", "bg", "vr_cover", "vr_path"]);
        $config = longbingGetAppConfig($this->_uniacid);
        if(isset($config["default_video"]) && empty($cardInfo["my_video"])) {
            $cardInfo["my_video"] = $config["default_video"];
        }
        if(isset($config["default_video_cover"]) && empty($cardInfo["my_video_cover"])) {
            $cardInfo["my_video_cover"] = $config["default_video_cover"];
        }
        if(isset($config["default_voice"]) && empty($cardInfo["bg"])) {
            $cardInfo["bg"] = $config["default_voice"];
        }
        if(isset($config["vr_cover"]) && empty($cardInfo["vr_cover"])) {
            $cardInfo["vr_cover"] = $config["vr_cover"];
        }
        if(isset($config["vr_path"]) && empty($cardInfo["vr_path"])) {
            $cardInfo["vr_path"] = $config["vr_path"];
            $cardInfo["vr_switch"] = $config["vr_switch"];
        }
        if(isset($config["vr_tittle"]) && empty($cardInfo["vr_tittle"])) {
            $cardInfo["vr_tittle"] = $config["vr_tittle"];
        }
        if(isset($cardInfo["my_video"]) && $cardInfo["my_video"]) {
            $cardInfo["my_video_vid"] = lbGetTencentVideo($cardInfo["my_video"]);
        }
        if(isset($cardInfo["vr_tittle"]) && !$cardInfo["vr_tittle"]) {
            $cardInfo["vr_tittle"] = "VR全景";
        }
        if(empty($input["is_update"])) {
            $defult_setting = new \app\card\model\DefaultSetting();
            $defult_setting_data = $defult_setting->settingInfo(["uniacid" => $this->_uniacid]);
            $defult_setting_data = transImages($defult_setting_data, ["my_photo_cover"]);
            $cardInfo["desc"] = !empty($cardInfo["desc"]) ? $cardInfo["desc"] : $defult_setting_data["my_sign"];
            $cardInfo["images"] = !empty($cardInfo["images"]) ? $cardInfo["images"] : $defult_setting_data["my_photo_cover"];
            $cardInfo["my_url"] = !empty($cardInfo["my_url"]) ? $cardInfo["my_url"] : $defult_setting_data["my_photo_link"];
            $cardInfo["voice"] = !empty($cardInfo["voice"]) ? $cardInfo["voice"] : $defult_setting_data["voice_text"];
            $cardInfo["voice_time"] = !empty($cardInfo["voice_time"]) ? $cardInfo["voice_time"] : $defult_setting_data["voice_time"];
        }
        $coupon_model = new \app\shop\model\IndexCoupon();
        foreach ($page_data["list"] as &$value) {
            if($value["type"] == "couponList" && empty($value["data"]["dataList"])) {
                $coupon_dis = ["status" => 1, "uniacid" => $this->_uniacid];
                $dataList = $coupon_model->couponListSelect($coupon_dis, $this->getUserId(), $staff_id);
                if(!empty($dataList)) {
                    if($value["data"]["type"] == 2) {
                        $value["data"]["dataList"] = $dataList;
                        $cardInfo["coupon"] = $dataList;
                    } else {
                        $cardInfo["coupon"] = $dataList[0];
                        $r_dis = ["coupon_id" => $dataList[0]["id"], "staff_id" => $staff_id, "uniacid" => $this->_uniacid];
                        $cardInfo["coupon_last_record"] = \app\card\model\CardCouponRecord::where($r_dis)->order("id desc")->limit(3)->select()->toArray();
                        if(!empty($cardInfo["coupon_last_record"])) {
                            foreach ($cardInfo["coupon_last_record"] as $index => $item) {
                                $user = longbingGetUser($item["user_id"], $this->_uniacid);
                                if(4 < mb_strlen($user["nickName"], "utf8")) {
                                    $user["nickName"] = mb_substr($user["nickName"], 0, 4, "UTF-8");
                                }
                                $cardInfo["coupon_last_record"][$index]["user_info"] = $user;
                            }
                        }
                    }
                }
            }
        }
        $modelCount = new \app\radar\model\RadarCount();
        list($viewCount, $thumbCount) = $modelCount->RadarNumber($staff_id, $this->_uniacid);
        $cardInfo["view_count"] = $viewCount;
        $cardInfo["thumbCount"] = $thumbCount;
        $checkVoice = \app\card\model\CardCount::where([["type", "=", 1], ["user_id", "=", $userId], ["to_uid", "=", $params["staff_id"]], ["sign", "=", "praise"]])->count();
        $checkThumb = \app\card\model\CardCount::where([["type", "=", 3], ["user_id", "=", $userId], ["to_uid", "=", $params["staff_id"]], ["sign", "=", "praise"]])->count();
        $radar_model = new \app\radar\model\RadarCount();
        $share_number = $radar_model->getShareNumber($params["staff_id"]);
        if($checkVoice) {
            $cardInfo["voiceThumbs"] = 1;
        } else {
            $cardInfo["voiceThumbs"] = 0;
        }
        if($checkThumb) {
            $cardInfo["isThumbs"] = 1;
        } else {
            $cardInfo["isThumbs"] = 0;
        }
        $cardInfo["view_count"] = $cardInfo["view_count"] + $cardInfo["view_number"];
        $cardInfo["thumbCount"] = $cardInfo["thumbCount"] + $cardInfo["t_number"];
        $cardInfo["share_number"] = $share_number;
        $modelTags = new \app\card\model\CardTags();
        $cardInfo["tag_list"] = $modelTags->cardTagList($params["staff_id"], $userId, $this->_uniacid);
        $eventCardInfoData = event("CardInfo", $params);
        foreach ($eventCardInfoData as $items) {
            foreach ($items as $key => $item) {
                if($key == "decorate") {
                    $cardInfo["plugin"] = $item;
                } else {
                    $cardInfo[$key] = $item;
                }
            }
        }
        $arr_data["card_info"] = $cardInfo;
        $arr_data["list"] = $page_data["list"];
        return $this->success($arr_data);
    }
    public function defaultSetting()
    {
        $d_model = new \app\card\model\DefaultSetting();
        $data = $d_model->settingInfo(["uniacid" => $this->_uniacid]);
        return $this->success($data);
    }
    public function getCardCount()
    {
        $userId = $this->getUserId();
        $uniacid = $this->_uniacid;
        $verify = ["staff_id" => "required"];
        $params = lbGetParamVerify($this->_param, $verify);
        $staff_id = $params["staff_id"];
        $cardInfo_default = longbingGetUserCard($staff_id, $this->_uniacid);
        if(empty($cardInfo_default) || empty($cardInfo_default["is_staff"])) {
            return $this->success([]);
        }
        $cardInfo = [];
        $modelCount = new \app\radar\model\RadarCount();
        list($cardInfo["view_list"]) = $modelCount->getCardViewInfo($params["staff_id"], $this->_uniacid);
        return $this->success($cardInfo);
    }
    public function editDesc()
    {
        $userId = $this->getUserId();
        $verify = ["desc" => ""];
        $params = lbGetParamVerify($this->_input, $verify);
        $card = \app\card\model\UserInfo::where([["fans_id", "=", $userId], ["is_staff", "=", 1], ["uniacid", "=", $this->_uniacid]])->field(["desc"])->find();
        if(!$card) {
            $this->error("card info not found", 402);
        }
        $card->desc = $params["desc"] ?? "";
        $result = $card->save();
        if($result === false) {
            $this->error("edit fail", 402);
        } else {
            $key = "longbing_card_info_" . $userId;
            delCache($key, $this->_uniacid);
        }
        longbingGetUserInfo($userId, $this->_uniacid, true);
        return $this->success([]);
    }
    public function editImages()
    {
        $userId = $this->getUserId();
        $verify = ["images" => "required"];
        $params = lbGetParamVerify($this->_input, $verify);
        $card = \app\card\model\UserInfo::where([["fans_id", "=", $userId], ["is_staff", "=", 1], ["uniacid", "=", $this->_uniacid]])->field(["images"])->find();
        if(!$card) {
            $this->error("card info not found", 402);
        }
        $params["images"] = implode(",", $params["images"]);
        $card->images = trim($params["images"], ",");
        $result = $card->save();
        if($result === false) {
            $this->error("edit fail", 402);
        } else {
            $key = "longbing_card_info_" . $userId;
            delCache($key, $this->_uniacid);
        }
        longbingGetUserInfo($userId, $this->_uniacid, true);
        return $this->success([]);
    }
    public function createCard()
    {
        $userId = $this->getUserId();
        $uniacid = $this->_uniacid;
        $verify = ["avatar" => "", "name" => "required", "job_id" => "required", "phone" => "required", "email" => "", "company_id" => "required", "auth_code" => "", "ww_account" => "", "telephone" => "", "wechat" => ""];
        $params = lbGetParamVerify($this->_input, $verify);
        $service_model = new \longbingcore\wxcore\WxSetting($this->_uniacid);
        $rest = $service_model->wxContentRlue($params["name"]);
        if($rest["errcode"] != 0) {
            return $this->error("内容含有违法违规内容");
        }
        $modelConfig = new \app\card\model\Config();
        $config = longbingGetAppConfig($this->_uniacid);
        $defaultCode = $config["code"];
        $companyInfo = $this->modelCompany->getInfo($this->_uniacid, 0, $params["company_id"]);
        if(!$companyInfo) {
            return $this->error(lang("not the company"));
        }
        $modelCompany = new \app\card\model\Company();
        $companyInfo = $modelCompany->changeTopName($companyInfo);
        $job_model = new \app\card\model\CardJob();
        $job = $job_model->getJob(["uniacid" => $uniacid, "id" => $params["job_id"]]);
        if(empty($job)) {
            return $this->error(lang("not the job"));
        }
        $companyCode = $companyInfo["auth_code"];
        $code = "";
        if($companyCode) {
            $code = $companyCode;
        }
        if(!$code && $defaultCode) {
            $code = $defaultCode;
        }
        $modelUserInfo = new \app\card\model\UserInfo();
        $userInfo = $modelUserInfo->where([["fans_id", "=", $userId], ["uniacid", "=", $this->_uniacid]])->find();
        $user = longbingGetUser($userId, $this->_uniacid);
        if($code && $code != $params["auth_code"] && empty($user["is_staff"])) {
            if(isset($params["auth_code"]) && !empty($params["auth_code"])) {
                if(isset($config["btn_code_err"]) && !empty($config["btn_code_err"])) {
                    return $this->error($config["btn_code_err"], 402);
                }
            } elseif(isset($config["btn_code_miss"]) && !empty($config["btn_code_miss"])) {
                return $this->error($config["btn_code_miss"], 402);
            }
            return $this->error(lang("code error"), 402);
        }
        if(empty($userInfo) || empty($userInfo["is_staff"])) {
            $permissions = longbingGetPluginAuth($this->_uniacid);
            if(!empty($permissions) && isset($permissions["card_number"]) && !empty($permissions["card_number"]) && longbingGetCardNum($this->_uniacid) >= $permissions["card_number"]) {
                return $this->error(lang("not card num"));
            }
        }
        if($userInfo) {
            $userInfo->avatar = $params["avatar"];
            $userInfo->name = $params["name"];
            $userInfo->job_id = $params["job_id"];
            $userInfo->phone = $params["phone"];
            $userInfo->email = $params["email"];
            $userInfo->company_id = $params["company_id"];
            $userInfo->ww_account = $params["ww_account"];
            $userInfo->telephone = $params["telephone"];
            $userInfo->wechat = !empty($params["wechat"]) ? $params["wechat"] : "";
            $userInfo->is_staff = 1;
            \app\card\model\User::update(["is_staff" => 1], ["id" => $userId]);
            $result = $userInfo->save();
            $key = "longbing_card_info_" . $userId;
            delCache($key, $this->_uniacid);
        } else {
            $modelUserInfo = new \app\card\model\UserInfo();
            $modelUserInfo->uniacid = $this->_uniacid;
            $modelUserInfo->fans_id = $userId;
            $modelUserInfo->avatar = $params["avatar"];
            $modelUserInfo->name = $params["name"];
            $modelUserInfo->job_id = $params["job_id"];
            $modelUserInfo->phone = $params["phone"];
            $modelUserInfo->email = $params["email"];
            $modelUserInfo->company_id = $params["company_id"];
            $modelUserInfo->ww_account = $params["ww_account"];
            $modelUserInfo->telephone = $params["telephone"];
            $modelUserInfo->wechat = $params["wechat"];
            $modelUserInfo->is_staff = 1;
            $modelUserInfo->auto_count = longbingGetUserInfoMinAutoCount($this->_uniacid);
            $modelUserInfo->is_default = 1;
            \app\card\model\User::update(["is_staff" => 1], ["id" => $userId]);
            $result = $modelUserInfo->save();
        }
        $permissions = new \app\boss\info\PermissionBoss($uniacid);
        if($permissions->pAuth()) {
            $bossData = \app\card\model\CardBoss::where([["user_id", "=", $userId], ["uniacid", "=", $this->_uniacid]])->find();
            if(empty($bossData)) {
                \app\card\model\CardBoss::create(["user_id" => $userId, "boss" => $params["company_id"], "uniacid" => $this->_uniacid]);
            }
        }
        if($result === false) {
            return $this->error("operation failed");
        }
        $file_path = "images/share_img/" . $uniacid . "/share-" . $userId . ".png";
        if(longbingHasLocalFile($file_path)) {
            unlink(FILE_UPLOAD_PATH . $file_path);
        }
        $params = transImagesOne($params, ["avatar"]);
        $gData = ["company_logo" => $companyInfo["logo"], "company_name" => longbingSortStr($companyInfo["name"], 10), "name" => longbingSortStr($params["name"], 10), "job" => longbingSortStr($job["name"], 10), "phone" => longbingSortStr($params["phone"], 12), "email" => longbingSortStr($params["email"], 18), "address" => longbingSortStr($companyInfo["addr"], 10), "img" => $params["avatar"]];
        if(empty($gData["company_logo"])) {
            $gData["company_logo"] = $this->defaultImage["image"];
        }
        if(empty($gData["img"])) {
            $gData["img"] = $this->defaultImage["avatar"];
        }
        try {
            $push_data = ["action" => "longbingCreateSharePng", "event" => "longbingCreateSharePng", "gData" => $gData, "user_id" => $userId, "uniacid" => $uniacid];
            publisher(json_encode($push_data, true));
        } catch (Exception $e) {
        }
        longbingGetUser($userId, $this->_uniacid, true);
        longbingGetUserInfo($userId, $this->_uniacid, true);
        return $this->success([]);
    }
    public function thumbStaff()
    {
        $userId = $this->getUserId();
        $verify = ["staff_id" => "required", "type" => 0];
        $params = lbGetParamVerify($this->_input, $verify);
        if($params["type"] == 0) {
            $check = \app\card\model\CardCount::where([["type", "=", 3], ["user_id", "=", $userId], ["to_uid", "=", $params["staff_id"]], ["sign", "=", "praise"]])->find();
            $type = 3;
        } else {
            $check = \app\card\model\CardCount::where([["type", "=", 1], ["user_id", "=", $userId], ["to_uid", "=", $params["staff_id"]], ["sign", "=", "praise"]])->find();
            $type = 1;
        }
        if($check) {
            $check = $check->toArray();
            $result = \app\card\model\CardCount::where([["id", "=", $check["id"]]])->delete();
        } else {
            $result = \app\card\model\CardCount::create(["type" => $type, "user_id" => $userId, "to_uid" => $params["staff_id"], "sign" => "praise", "uniacid" => $this->_uniacid]);
        }
        return $this->success([]);
    }
    public function thumbTag()
    {
        $userId = $this->getUserId();
        $verify = ["tag_id" => "required"];
        $params = lbGetParamVerify($this->_input, $verify);
        $check = \app\card\model\CardUserTags::where([["user_id", "=", $userId], ["tag_id", "=", $params["tag_id"]]])->find();
        if($check) {
            \app\card\model\CardUserTags::where([["id", "=", $check["id"]]])->delete();
            \app\card\model\CardTags::where([["id", "=", $check["tag_id"]]])->dec("count")->update();
        } else {
            \app\card\model\CardUserTags::create(["user_id" => $userId, "tag_id" => $params["tag_id"], "uniacid" => $this->_uniacid]);
            \app\card\model\CardTags::where([["id", "=", $params["tag_id"]]])->inc("count")->update();
        }
        return $this->success([]);
    }
    public function getFormIdFromMini()
    {
        $userId = $this->getUserId();
        $verify = ["form_id" => "required"];
        $params = lbGetParamVerify($this->_input, $verify);
        $data = explode(",", $params["form_id"]);
        $insertData = [];
        foreach ($data as $index => $item) {
            if($item !== "the formId is a mock one") {
                $insertData[] = ["user_id" => $userId, "formId" => $item, "uniacid" => $this->_uniacid];
            }
        }
        if(empty($insertData)) {
            return $this->success([]);
        }
        $push_data = ["action" => "longbingSaveFormId", "event" => "longbingSaveFormId", "data" => $insertData];
        publisher(json_encode($push_data, true));
        return $this->success([]);
    }
    public function reportPhone()
    {
        $userId = $this->getUserId();
        $verify = ["staff_id" => "required", "encryptedData" => "required", "iv" => "required"];
        $params = lbGetParamVerify($this->_input, $verify);
        $staff_id = $params["staff_id"];
        $uniacid = $this->_uniacid;
        $encryptedData = $params["encryptedData"];
        $iv = $params["iv"];
        $info = \app\card\model\UserPhone::where([["user_id", "=", $userId], ["uniacid", "=", $uniacid]])->find();
        if($info) {
            return $this->success(["phone" => $info["phone"], "new" => 3, "iv" => $iv]);
        }
        $config = longbingGetAppConfig($this->_uniacid);
        $appid = $config["appid"];
        $appsecret = $config["app_secret"];
        $check_sk = \app\card\model\UserSk::where([["user_id", "=", $userId]])->find();
        if(!$check_sk) {
            return $this->error(-1, "need login", []);
        }
        $session_key = $check_sk["sk"];
        $data = NULL;
        $errCode = decryptDataLongbing($appid, $session_key, $encryptedData, $iv, $data);
        if($errCode == 0) {
            $data = json_decode($data, true);
            $phone = $data["purePhoneNumber"];
            $data = ["user_id" => $userId, "to_uid" => $params["staff_id"], "phone" => $phone, "uniacid" => $uniacid];
            $data = \app\card\model\UserPhone::create($data);
            if(!empty($data)) {
                $user = longbingGetUser($userId, $this->_uniacid);
                $user["phone"] = $phone;
                longbingSetUser($userId, $this->_uniacid, $user);
            }
            return $this->success(["phone" => $phone, "new" => 1]);
        }
        return $this->error($errCode);
    }
    public function baiduReportPhone()
    {
        $userId = $this->getUserId();
        $verify = ["staff_id" => "required", "encryptedData" => "required", "iv" => "required"];
        $params = lbGetParamVerify($this->_input, $verify);
        $staff_id = $params["staff_id"];
        $uniacid = $this->_uniacid;
        $encryptedData = $params["encryptedData"];
        $iv = $params["iv"];
        $info = \app\card\model\UserPhone::where([["user_id", "=", $userId], ["uniacid", "=", $uniacid]])->find();
        if($info) {
            return $this->success(["phone" => $info["phone"], "new" => 3, "iv" => $iv]);
        }
        $config = \think\facade\Db::name("longbing_card_baidu_setting")->where(["uniacid" => $this->_uniacid])->find();
        $appid = $config["client_id"];
        $appsecret = $config["client_secret"];
        $check_sk = \app\card\model\UserSk::where([["user_id", "=", $userId]])->find();
        if(!$check_sk) {
            return $this->error(-1, "need login", []);
        }
        $session_key = $check_sk["sk"];
        $data = NULL;
        $errCode = baiduDecryptDataLongbing($encryptedData, $iv, $appid, $session_key);
        if($errCode) {
            $errCode = json_decode($errCode, true);
            $phone = $errCode["mobile"];
            $data = ["user_id" => $userId, "to_uid" => $params["staff_id"], "phone" => $phone, "uniacid" => $uniacid];
            $data = \app\card\model\UserPhone::create($data);
            if(!empty($data)) {
                $user = longbingGetUser($userId, $this->_uniacid);
                $user["phone"] = $phone;
                longbingSetUser($userId, $this->_uniacid, $user);
            }
            return $this->success(["phone" => $phone, "new" => 1]);
        }
        return $this->error($errCode);
    }
    public function reviewTags()
    {
        $userId = $this->getUserId();
        $staffTags = \app\card\model\CardTags::where([["user_id", "=", $userId], ["uniacid", "=", $this->_uniacid], ["status", "=", 1]])->field(["id", "tag", "count"])->select()->toArray();
        $sysTags = \app\card\model\CardTags::where([["user_id", "=", 0], ["uniacid", "=", $this->_uniacid], ["status", "=", 1]])->field(["id", "tag", "count"])->select()->toArray();
        foreach ($sysTags as $index => $item) {
            $sysTags[$index]["selected"] = 0;
            foreach ($staffTags as $index2 => $item2) {
                if($item2["tag"] == $item["tag"]) {
                    $sysTags[$index]["selected"] = 1;
                }
            }
        }
        $data["staffTags"] = $staffTags;
        $data["sysTags"] = $sysTags;
        return $this->success($data);
    }
    public function editTags()
    {
        $userId = $this->getUserId();
        $verify = ["tags" => "required"];
        $params = lbGetParamVerify($this->_input, $verify);
        $model = new \app\card\model\CardTags();
        $staffTags = $model->where([["user_id", "=", $userId], ["uniacid", "=", $this->_uniacid], ["status", "=", 1]])->field(["id", "tag", "count"])->select()->toArray();
        $tmpArr = [];
        $updateData = [];
        foreach ($staffTags as $index => $item) {
            $tmpArr[] = $item["tag"];
            if(!in_array($item["tag"], $params["tags"])) {
                $updateData[] = ["id" => $item["id"], "status" => -1];
            }
        }
        if(!empty($updateData)) {
            $model->saveAll($updateData);
        }
        $insertData = [];
        foreach ($params["tags"] as $index => $item) {
            if(!in_array($item, $tmpArr)) {
                $insertData[] = ["user_id" => $userId, "tag" => $item, "count" => 0, "uniacid" => $this->_uniacid, "status" => 1, "top" => 0];
            }
        }
        if(!empty($insertData)) {
            $model->saveAll($insertData);
        }
        return $this->success([]);
    }
    public function collectionCard()
    {
        $userInfo = $this->getUserInfo();
        $userId = $this->getUserId();
        $input = $this->_input;
        if(isset($input["collection"])) {
            $input = $input["collection"];
        }
        if(!isset($input["staff_id"]) || empty($input["staff_id"])) {
            return $this->success([]);
        }
        $check_filter = ["uniacid" => $this->_uniacid, "uid" => $userId, "to_uid" => $input["staff_id"]];
        $check = $this->modelCollection->checkCollection($check_filter);
        if(!empty($check) && isset($check["status"]) && in_array($check["status"], ["1", 1])) {
            return $this->success([]);
        }
        $staff = longbingGetUserInfo($input["staff_id"], $this->_uniacid);
        if(!isset($staff["is_staff"]) || empty($staff["is_staff"])) {
            return $this->success([]);
        }
        if(isset($input["from_uid"])) {
            $from_user = longbingGetUser($input["from_uid"], $this->_uniacid);
            if(!empty($from_user)) {
                $check_filter["from_uid"] = $input["from_uid"];
            }
        }
        if(isset($input["encryptedData"])) {
            if(!isset($input["iv"])) {
                $input["iv"] = "";
            }
            $sk = longbingGetUserSk($userId, $this->_uniacid);
            $appid = NULL;
            $config = longbingGetAppConfig($this->_uniacid);
            if(isset($config["appid"]) && !empty($config["appid"])) {
                $appid = $config["appid"];
            }
            if(!empty($sk) && !empty($appid)) {
                $data = NULL;
                $errCode = decryptDataLongbing($appid, $sk, $input["encryptedData"], $input["iv"], $data);
                if($errCode == 0) {
                    $data = json_decode($data, true);
                    $check_filter["openGId"] = $data["openGId"];
                }
            }
        }
        if(isset($input["scene"])) {
            $check_filter["scene"] = $input["scene"];
        }
        if(isset($input["type"])) {
            $check_filter["type"] = $input["type"];
        }
        $result = false;
        if(empty($check)) {
            $result = $this->modelCollection->createCollection($check_filter);
        } else {
            $check_filter["status"] = 1;
            $result = $this->modelCollection->updateCollection(["id" => $check["id"]], $check_filter);
        }
        return $this->success([]);
    }
    public function unCollectionCard()
    {
        $userInfo = $this->getUserInfo();
        $userId = $this->getUserId();
        $input = $this->_input;
        if(isset($input["collection"])) {
            $input = $input["collection"];
        }
        if(!isset($input["staff_id"]) || empty($input["staff_id"])) {
            return $this->error(lang("not staff id ,please check param."));
        }
        $check_filter = ["uniacid" => $this->_uniacid, "uid" => $userId, "to_uid" => $input["staff_id"]];
        $check = $this->modelCollection->checkCollection($check_filter);
        if(empty($check) || !isset($check["status"]) || !in_array($check["status"], ["1", 1])) {
            return $this->error(lang("the card has not been collected ,Please collect"));
        }
        $result = $this->modelCollection->updateCollection(["id" => $check["id"]], ["status" => 0]);
        return $this->success($result);
    }
    public function getWxCode()
    {
        $input = NULL;
        if(isset($this->_input["data"])) {
            $input = $this->_input["data"];
        }
        if(empty($input)) {
            return $this->error("not data ,please check input data.");
        }
        $input["user_id"] = $this->_user_id;
        $result = longbingCreateWxCode($this->_uniacid, $input);
        return $this->success($result);
    }
    public function getWxCodeData()
    {
        $code_id = NULL;
        if(isset($this->_param["code_id"])) {
            $code_id = $this->_param["code_id"];
        }
        if(empty($code_id)) {
            return $this->error("not code id ,please check param.");
        }
        $result = longbingGetWxCode($code_id, $this->_uniacid, $is_update = false);
        return $this->success($result);
    }
    public function getImage()
    {
        $path = $this->_param["path"] ?? "http://longbing.cncnconnect.com/attachment/image/2/wxcode/8e1cc25f24bd0c10ad238e1ce8b7a2e2.jpeg";
        if(!$path) {
            return $this->error("请传入参数");
        }
        $type_img = getimagesize($path);
        ob_start();
        if(strpos($type_img["mime"], "jpeg")) {
            $resourch = imagecreatefromjpeg($path);
            imagejpeg($resourch);
        } elseif(strpos($type_img["mime"], "png")) {
            $resourch = imagecreatefrompng($path);
            imagepng($resourch);
        }
        $content = ob_get_clean();
        imagedestroy($resourch);
        return response($content, 200, ["Content-Length" => strlen($content)])->contentType("image/png");
    }
    public function formIds()
    {
        global $_GPC;
        global $_W;
        $uid = $this->_user_id ?? $_GPC["user_id"] ?? NULL;
        $beginTime = mktime(0, 0, 0, date("m"), date("d") - 7, date("Y"));
        $m_form_id = new \app\Common\model\LongbingCardFromId();
        $count = $m_form_id->where([["uniacid", "=", $this->_uniacid], ["user_id", "=", $uid], ["create_time", ">", $beginTime]])->count();
        return $this->success(["count" => $count]);
    }
    public function clearCardInfoVoice()
    {
        $userId = $this->getUserId();
        $card = longbingGetUserInfo($userId, $this->_uniacid);
        if(!$card) {
            return $this->success([]);
        }
        $result = $this->modelUserInfo->updateUser(["fans_id" => $userId], ["voice" => NULL, "voice_time" => 0]);
        if(!empty($result)) {
            longbingGetUserInfo($userId, $this->_uniacid, true);
        }
        return $this->success([]);
    }
    public function getQr()
    {
        $input = $this->_input;
        $qr = getCache($this->getUserId() . "-" . $input["type"] . "-" . $input["staff_id"] . "-" . $input["id"] . "-qr", $this->_uniacid);
        if(empty($qr)) {
            $user = $this->getUserInfo();
            $input["user_id"] = $this->getUserId();
            $input["pid"] = $user["pid"];
            $data = longbingCreateWxCode($this->_uniacid, $input, $input["page"]);
            $data = transImagesOne($data, ["qr_path"], $this->_uniacid);
            $qr = $data["qr_path"];
            setCache($this->getUserId() . "-" . $input["type"] . "-" . $input["staff_id"] . "-" . $input["id"] . "-qr", $qr, 3600, $this->_uniacid);
        }
        return $this->success($qr);
    }
    public function authStatus()
    {
        $user_id = $this->getUserId();
        $is_staff = (new \app\card\model\User())->where("id", "=", $user_id)->value("is_staff");
        $info = longbing_auth_status($this->_uniacid);
        $info["is_staff"] = $is_staff;
        return $this->success($info);
    }
}

?>